﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcTodo.Controllers
{
    public class TodoController : Controller
    {
        //
        // GET: /Todo/

        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(Models.Todo todo)
        {
            if (ModelState.IsValid)
            {
                using (var db = new Models.TodoModelContainer())
                {
                    db.Todoes.AddObject(todo);
                    db.SaveChanges();
                    return RedirectToAction("Index", "Home");
                }
            }

            return View(todo);
        }

        public ActionResult Today()
        {
            using (var db = new Models.TodoModelContainer())
            {
                var qry = from it in db.Todoes
                          where it.TodoDate == DateTime.Today
                          select it;
                var data = qry.ToList();

                return PartialView(data);
            }
        }

        public ActionResult Other()
        {
            using (var db = new Models.TodoModelContainer())
            {
                var qry = from it in db.Todoes
                          where it.TodoDate != DateTime.Today
                          select it;
                var data = qry.ToList();

                return PartialView(data);
            }
        }

    }
}
